//
//  SelectFriendCell.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/20.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "SelectFriendCell.h"
#import "ZZRadioControl.h"

@interface SelectFriendCell()<ZZRadioControlDelegate>

@property (nonatomic, strong) UIImageView *avatar_image_view;
@property (nonatomic, strong) UILabel *username_label;
@property (nonatomic, strong) UILabel *flower_num_label;
@property (nonatomic, strong) ZZRadioControl *radioControl;
@property (nonatomic, strong) UIView *bgView;

@end

@implementation SelectFriendCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self makeSelectFriendCell];
        
    }
    return self;
}

- (void)makeSelectFriendCell
{
    _bgView = [UIView new];
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    
    _avatar_image_view = [UIImageView new];
    _avatar_image_view.layer.masksToBounds = YES;
    _avatar_image_view.layer.cornerRadius = 18;
    _avatar_image_view.backgroundColor = [UIColor yellowColor];
    [_bgView addSubview:_avatar_image_view];
    [_avatar_image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.bottom.mas_equalTo(-6);
        make.left.mas_equalTo(30);
        make.width.mas_equalTo(36);
    }];
    
    _radioControl = [[ZZRadioControl alloc]init];
    [_bgView addSubview:_radioControl];
    [_radioControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(11);
        make.bottom.mas_equalTo(-11);
        make.right.mas_equalTo(-30);
        make.width.mas_equalTo(26);
    }];
    
    [ZZRadioControl addObserverForGroupId:@"Group1" observer:self];
    
    _username_label = [UILabel new];
    _username_label.textColor = [UIColor blackColor];
    _username_label.font = [UIFont systemFontOfSize:17.0f];
    [_bgView addSubview:_username_label];
    [_username_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(_avatar_image_view.mas_right).mas_offset(30);
        make.width.mas_equalTo(SCREEN_WIDTH / 3);
    }];

}

- (void)loadFriendData:(FriendModel *)friendModel index:(NSInteger)index
{
    _radioControl.groupId = @"Group1";
    _radioControl.index = index;
    
    [_avatar_image_view sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseIp,friendModel.friendInfo.avatar]]];
    
    _username_label.text = friendModel.remarks;
    
    if (index % 2 == 0) {
        _bgView.backgroundColor = RGB(245, 242, 242);
    }else{
        _bgView.backgroundColor = [UIColor whiteColor];
    }
}

- (void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId
{
    _selectData(index);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
